package com.huicoo.forestmanager.ui.patrol.PatrolRecordFragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;

import com.huicoo.forestmanager.R;
import com.huicoo.forestmanager.adapter.PatrolRecordAdapter;
import com.huicoo.forestmanager.base.BaseFragment;
import com.huicoo.forestmanager.network.bean.patrol.GetquerymonthBean;
import com.huicoo.forestmanager.ui.patrol.PatrolRecordChildFragment.PatrolRecordChildFragment;
import com.huicoo.forestmanager.ui.patrol.PatrolRecordFragment.contract.PatrolRecordFragmentContract;
import com.huicoo.forestmanager.ui.patrol.PatrolRecordFragment.presenter.PatrolRecordFragmentPresenter;
import com.huicoo.forestmanager.widget.LoadingDialog;

import butterknife.BindView;

/**
 * --------- 日期 ------- 维护人 ------------ 变更内容 --------
 * 2019/4/5		    Administrator
 * <p>
 * 巡查记录片段
 */
public class PatrolRecordFragment extends BaseFragment implements PatrolRecordFragmentContract.View {

    @BindView(R.id.tab_Layout)
    TabLayout tab_Layout;

    @BindView(R.id.view_pager)
    ViewPager view_pager;


    LoadingDialog loadingDialog;

    public static PatrolRecordFragment getInstance() {
        return new PatrolRecordFragment();
    }


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_patrol_record;
    }

    @Override
    protected void initView() {

        // 初始化P层
        presenter = new PatrolRecordFragmentPresenter(this);
        ((PatrolRecordFragmentPresenter) presenter).getquerymonth();
        if (loadingDialog == null) {
            loadingDialog = new LoadingDialog(getActivity());
            loadingDialog.show();
        }

        view_pager.setOffscreenPageLimit(1);
    }




    @Override
    public void getquerymonthSuccess(GetquerymonthBean bean) {
        if (bean.getData().size()>0 && bean.getData()!=null){
            //(片段得到支持经理)
            PatrolRecordAdapter pageAdapter = new PatrolRecordAdapter(getChildFragmentManager());
            for (int i = 0; i < bean.getData().size(); i++) {
                PatrolRecordChildFragment instance = PatrolRecordChildFragment.getInstance();
                Bundle bundle = new Bundle();
                bundle.putString("Value", bean.getData().get(i).getValue());
                instance.setArguments(bundle);
                pageAdapter.addFragmentPager(bean.getData().get(i).getName(),instance);//片段
            }
            view_pager.setAdapter(pageAdapter);//设置适配器
            //标签布局绑定视图页
            tab_Layout.setupWithViewPager(view_pager);//在viewpader的适配器里面设置标签布局的标题
        }
        loadingDialog.dismiss();
    }

    @Override
    public void getquerymonthFail(String msg) {
        loadingDialog.dismiss();
    }
}
